package com.domcer.ultra.menu.engine;

import com.domcer.ultra.menu.common.constants.RequireTypeEnum;
import com.domcer.ultra.menu.common.utils.FormatUtil;
import common.utils.MessageUtil;
import common.utils.StringUtils;
import org.bukkit.entity.Player;

import java.util.List;

/**
 * @Author Sensen
 * @Date 2025/1/31 17:40
 */
public class RequireManager {

    public static boolean execute(Player player, List<String> requires) {
        //If true, can open the menu or show item
        for (String require : requires) {
            if (!execute(player, require)) {
                return false;
            }
        }
        return true;
    }

    public static boolean execute(Player player, String require){
        //If true, require pass
        String[] parse = FormatUtil.parse(require);
        if (parse != null) {
            String requireType = parse[0];
            String content = MessageUtil.exchangeMessage(StringUtils.isNotEmpty(parse[1]) ? parse[1] : "", player);
            RequireTypeEnum requireTypeEnum = RequireTypeEnum.getByName(requireType);
            return requireTypeEnum.getRequire().execute(player, content);
        }
        return true;
    }
}
